// Include files.
#include <vector>
#include "SystematicRobot.hpp"
#include "ControllerSelectorController.hpp"

using namespace std;

/**
 *  Constructor for ControllerSelectorController.
 * 	
 * 	@param upInput Input for selecting up the list.  User is still reposible for deletion of parameter.
 * 	@param downInput Input for selecting down the list.  User is still reposible for deletion of parameter.
 *  @param valueOutput Value output for outputing the name of the selected controller.
 */
ControllerSelectorController::ControllerSelectorController(HumanDigitalInput &upInput, HumanDigitalInput &downInput, ValueOutput<std::string> &valueOutput) :
	SelectorController<Item>(upInput, downInput, valueOutput),
	m_robot(NULL)
{
}

/**
 *  Constructor for ControllerSelectorController.
 * 	
 * 	@param driverStationIo Driver station IO.  User is still reposible for deletion of parameter.
 *  @param buttonUp Channel number for button for selecting up the list.
 *  @param buttonDown Channel number for button for selecting down the list.
 *  @param valueOutput Value output for outputing the name of the selected controller.
 */
ControllerSelectorController::ControllerSelectorController(DriverStationEnhancedIO &driverStationIo, UINT32 buttonUp, UINT32 buttonDown, ValueOutput<std::string> &valueOutput) :
	SelectorController<Item>(driverStationIo, buttonUp, buttonDown, valueOutput),
	m_robot(NULL)
{
}

ControllerSelectorController::~ControllerSelectorController()
{
}

void ControllerSelectorController::HandleAddedToRobot(SystematicRobot &robot)
{
	m_robot = &robot;
	
	vector<NameItemPairType>::const_iterator it;
	
	for (it = GetNameItemPairs().begin(); it != GetNameItemPairs().end(); ++it)
	{
		m_robot->AddController(*(it->second));
	}
}

void ControllerSelectorController::HandleItemAdded(RobotController *controller)
{
	if (m_robot != NULL)
		m_robot->AddController(*controller);
}

void ControllerSelectorController::HandleItemSelectedImpl(RobotController *controller)
{
	controller->Activate();
}

void ControllerSelectorController::HandleItemUnselectedImpl(RobotController *controller)
{
	controller->Deactivate();
}
